package com.tencent.wxcloudrun.vo.response.card;

import com.tencent.wxcloudrun.domain.TStoreCard;
import com.tencent.wxcloudrun.domain.TUserCardApply;
import com.tencent.wxcloudrun.domain.TUserCardApplyImg;
import com.tencent.wxcloudrun.util.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/22
 * @Description 查询申请卡片请求出参
 */
@Data
@ApiModel(value = "UserCardQueryApplyResVo", description = "查询申请卡片请求出参")
public class UserCardQueryApplyResVo {

    @ApiModelProperty("卡片序号")
    private Long cardId;

    @ApiModelProperty("卡片名称")
    private String cardName;

    @ApiModelProperty("申请状态")
    private Integer status;

    @ApiModelProperty("卡片数量")
    private Integer count;

    @ApiModelProperty("申请描述")
    private String memo;

    @ApiModelProperty("拒绝原因")
    private String reason;

    @ApiModelProperty("申请时间")
    private String createdTime;

    @ApiModelProperty("上传图片列表")
    private List<String> imgUrlList;

    public void build(TUserCardApply apply, TStoreCard card, List<TUserCardApplyImg> applyImgList) {
        if (Objects.nonNull(apply)) {
            this.setCardId(apply.getCardId());
            this.setCardName(card.getName());
            this.setStatus(apply.getStatus());
            this.setCount(apply.getCount());
            this.setMemo(apply.getMemo());
            this.setReason(apply.getReason());
            this.setCreatedTime(apply.getCreatedTime().format(DateUtils.LOCAL_DATE_TIME_FORMATTER));
        }
        if (!CollectionUtils.isEmpty(applyImgList)) {
            this.setImgUrlList(new ArrayList<>(applyImgList.size()));
            for (TUserCardApplyImg tUserCardApplyImg : applyImgList) {
                this.getImgUrlList().add(tUserCardApplyImg.getImgUrl());
            }
        }
    }

}
